<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${movie.title} - 电影详情</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .movie-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 3rem 0;
        }
        .movie-poster {
            width: 100%;
            max-width: 300px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
        }
        .movie-info h1 {
            font-size: 2.5rem;
            font-weight: bold;
            margin-bottom: 1rem;
        }
        .movie-meta {
            font-size: 1.1rem;
            margin-bottom: 0.8rem;
            opacity: 0.9;
        }
        .movie-meta i {
            width: 20px;
            text-align: center;
        }
        .rating-badge {
            background: rgba(255, 255, 255, 0.2);
            padding: 0.5rem 1rem;
            border-radius: 25px;
            font-size: 1.1rem;
            font-weight: bold;
            display: inline-block;
            margin-top: 1rem;
        }
        .content-section {
            padding: 3rem 0;
        }
        .synopsis-card {
            background: white;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            padding: 2rem;
            margin-bottom: 2rem;
        }
        .action-buttons .btn {
            padding: 0.8rem 2rem;
            font-size: 1.1rem;
            border-radius: 25px;
            margin: 0.5rem;
        }
        .btn-book {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            color: white;
        }
        .btn-book:hover {
            background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
            color: white;
        }
        .genre-tag {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 0.3rem 0.8rem;
            border-radius: 15px;
            font-size: 0.9rem;
            margin-right: 0.5rem;
            display: inline-block;
        }
        .trailer-section {
            background: #f8f9fa;
            padding: 3rem 0;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
        <div class="container">
            <a class="navbar-brand fw-bold" href="${pageContext.request.contextPath}/movies" style="color: #667eea;">
                <i class="fas fa-film me-2"></i>在线影院
            </a>
            
            <div class="navbar-nav ms-auto">
                <a class="nav-link" href="${pageContext.request.contextPath}/movies">
                    <i class="fas fa-home me-1"></i>首页
                </a>
                <c:if test="${not empty sessionScope.user}">
                    <a class="nav-link" href="${pageContext.request.contextPath}/user/orders">
                        <i class="fas fa-ticket-alt me-1"></i>我的订单
                    </a>
                    <a class="nav-link" href="${pageContext.request.contextPath}/logout">
                        <i class="fas fa-sign-out-alt me-1"></i>退出
                    </a>
                </c:if>
                <c:if test="${empty sessionScope.user}">
                    <a class="nav-link" href="${pageContext.request.contextPath}/login">
                        <i class="fas fa-sign-in-alt me-1"></i>登录
                    </a>
                </c:if>
            </div>
        </div>
    </nav>

    <!-- 电影信息头部 -->
    <section class="movie-header">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-4 text-center">
                    <img src="${movie.posterUrl != null ? movie.posterUrl : '/images/default-poster.jpg'}" 
                         class="movie-poster" alt="${movie.title}">
                </div>
                <div class="col-md-8">
                    <div class="movie-info">
                        <h1>${movie.title}</h1>
                        <c:if test="${not empty movie.englishTitle}">
                            <div class="movie-meta">
                                <i class="fas fa-globe"></i>${movie.englishTitle}
                            </div>
                        </c:if>
                        <div class="movie-meta">
                            <i class="fas fa-user-tie"></i>导演：${movie.director}
                        </div>
                        <c:if test="${not empty movie.actors}">
                            <div class="movie-meta">
                                <i class="fas fa-users"></i>主演：${movie.actors}
                            </div>
                        </c:if>
                        <div class="movie-meta">
                            <i class="fas fa-clock"></i>时长：${movie.duration}分钟
                        </div>
                        <c:if test="${not empty movie.language}">
                            <div class="movie-meta">
                                <i class="fas fa-language"></i>语言：${movie.language}
                            </div>
                        </c:if>
                        <c:if test="${not empty movie.country}">
                            <div class="movie-meta">
                                <i class="fas fa-flag"></i>制片国家/地区：${movie.country}
                            </div>
                        </c:if>
                        <c:if test="${not empty movie.releaseDate}">
                            <div class="movie-meta">
                                <i class="fas fa-calendar"></i>上映日期：<fmt:formatDate value="${movie.releaseDate}" pattern="yyyy年MM月dd日"/>
                            </div>
                        </c:if>
                        
                        <div class="mt-3">
                            <span class="genre-tag">${movie.genre}</span>
                        </div>
                        
                        <c:if test="${not empty movie.rating}">
                            <div class="rating-badge">
                                <i class="fas fa-star me-1"></i>评分：${movie.rating}
                            </div>
                        </c:if>
                        
                        <!-- 操作按钮 -->
                        <div class="action-buttons mt-4">
                            <c:choose>
                                <c:when test="${not empty showtimes}">
                                    <button type="button" class="btn btn-book btn-lg" onclick="bookMovie(${movie.id})">
                                        <i class="fas fa-ticket-alt me-2"></i>立即订票
                                    </button>
                                </c:when>
                                <c:otherwise>
                                    <button type="button" class="btn btn-secondary btn-lg" disabled>
                                        <i class="fas fa-calendar-times me-2"></i>暂无场次
                                    </button>
                                </c:otherwise>
                            </c:choose>
                            <a href="${pageContext.request.contextPath}/movies" class="btn btn-outline-light btn-lg">
                                <i class="fas fa-arrow-left me-2"></i>返回列表
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 剧情简介 -->
    <section class="content-section">
        <div class="container">
            <div class="synopsis-card">
                <h3 class="mb-3">
                    <i class="fas fa-file-alt me-2" style="color: #667eea;"></i>剧情简介
                </h3>
                <c:choose>
                    <c:when test="${not empty movie.synopsis}">
                        <p class="lead">${movie.synopsis}</p>
                    </c:when>
                    <c:otherwise>
                        <p class="text-muted">暂无剧情简介</p>
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
    </section>

    <!-- 预告片区域 -->
    <c:if test="${not empty movie.trailerUrl}">
        <section class="trailer-section">
            <div class="container">
                <h3 class="text-center mb-4">
                    <i class="fas fa-play-circle me-2" style="color: #667eea;"></i>预告片
                </h3>
                <div class="row justify-content-center">
                    <div class="col-md-8">
                        <div class="ratio ratio-16x9">
                            <iframe src="${movie.trailerUrl}" allowfullscreen></iframe>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </c:if>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        function bookMovie(movieId) {
            <c:if test="${empty sessionScope.user}">
                alert('请先登录后再订票');
                window.location.href = '${pageContext.request.contextPath}/login';
                return;
            </c:if>
            
            window.location.href = '${pageContext.request.contextPath}/showtimes?movieId=' + movieId;
        }
    </script>
</body>
</html>
